package com.simple.cloud.mapper;

import com.mybatisflex.core.BaseMapper;
import com.simple.cloud.domain.entity.SysMenu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenu> {
    @Select("<script>" +
            "select menu.* from sys_menu menu left join sys_role_menu rm on menu.id = rm.menu_id where rm.role_id = #{id} " +
            "</script>")
    Set<SysMenu> selectMenusByRoleId(Long id);

    @Select("<script>" +
            "select menu.* from sys_user_role ur " +
            "    left join sys_role role on ur.role_id = role.id " +
            "    left join sys_role_menu rm on role.id = rm.role_id " +
            "    left join sys_menu menu on rm.menu_id = menu.id " +
            "    where ur.user_id = #{id} " +
            "</script>")
    Set<SysMenu> selectMenusByUserId(Long id);
}
